package jsyf.oa.dao.wreport;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.dao.BaseJdbcDao;
import jsyf.oa.entity.wreport.WReportExpensesEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: @张巨波 @zhangjubo
 * @creat: on 2017/12/1.
 * @since: V1.0.0
 * @see jsyf.oa.web
 */
@Repository
public class WReportExpensesDao extends BaseDao {

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
       // return JSON.toJavaObject(json, WReportExpensesEntity.class);
        return null;
    }
    /**
     * 根据条件查询
     * @param condition
     * @param params
     * @return
     */
    public List<JSONObject> getByCondition(String condition, Object[] params){
        return this.getByPage(condition,params,1,Integer.MAX_VALUE);
    }
    public List<JSONObject> getByPage(String condition,Object[] params, int requestPage, int pageSize){
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT \n");
        sql.append(" expenses.ID AS id, \n");
        sql.append(" expenses.NAME AS name, \n");
        sql.append(" expenses.PARENT_ID AS parentId, \n");
        sql.append(" expenses.PHONE_NAME AS phoneName, \n");
        sql.append(" expenses.TEMPORARY_COST AS temporaryCost,\n");
        sql.append(" CASE PHONE_NAME WHEN \"现金加油费\" THEN 1");
        sql.append("  WHEN \"住宿费\" THEN 2");
        sql.append(" WHEN \"招待费\" THEN 3");
        sql.append(" WHEN \"私车公用\" THEN 4");
        sql.append(" WHEN \"其他\" THEN 5");
        sql.append(" END AS sortNo ");
        sql.append(" FROM T_WRT_EXPENSES AS expenses \n");
        sql.append(" WHERE 1 = 1 \n");
        sql.append(condition);
        sql.append(" ORDER BY sortNo");
        super.appendPageSql(sql,requestPage,pageSize);

        List<JSONObject> expensesList = super.queryForJsonList(sql.toString(),params);

        return expensesList;
    }
   public List<JSONObject> getOilList(String condition,Object[] params){
       StringBuffer sql = new StringBuffer();
       sql.append(" SELECT");
       sql.append(" t_sys_role_name_2_expenses.ROLE_NAME_ID AS roleNameId,");
       sql.append(" t_wrt_expenses.ID as id,");
       sql.append(" t_wrt_expenses.PHONE_NAME as phoneName,");
       sql.append(" CASE PHONE_NAME WHEN \"现金加油费\" THEN 1");
       sql.append("  WHEN \"油卡加油费\" THEN 2");
       sql.append("  WHEN \"住宿费\" THEN 3");
       sql.append(" WHEN \"招待费\" THEN 4");
       sql.append(" WHEN \"私车公用\" THEN 5");
       sql.append(" WHEN \"其他\" THEN 6");
       sql.append(" END AS sortNo ");
       sql.append(" FROM t_sys_role_name_2_expenses");
       sql.append(" LEFT JOIN t_wrt_expenses ON t_sys_role_name_2_expenses.EXPENSES_ID =t_wrt_expenses.ID");
       sql.append(" WHERE 1=1");
       sql.append(condition);
       sql.append(" ORDER BY sortNo");
       List<JSONObject> getOilList = super.queryForJsonList(sql.toString(),params);
       return  getOilList;
   }


}
